#include<bits/stdc++.h>
using namespace std;
int T,m,n,l,lmt,c[100010],d[100010],v[100010],a;
int main(){
freopen("detect.in","r",stdin);
freopen("detect.out","w",stdout);
ios::sync_with_stdio(false);
cin>>T;
for(int i=1;i<=T;i++){
    cin>>m>>n>>l>>lmt;
    for(int j=1;j<=m;j++){
        cin>>d[j]>>v[j]>>a;
    }
    for(int j=1;j<=n;j++){
        cin>>c[j];
    }
    for(int j=1;j<=m;j++){
        if(v[j]>lmt&&d[j]<=c[n]){
            cout<<1;
        }
        else{
            cout<<0;
        }
    }



}
return 0;
}
